package ma.myschool.app.service.impl;

import java.util.ArrayList;
import java.util.List;

import ma.myschool.app.dao.EleveDao;
import ma.myschool.app.model.Eleve;
import ma.myschool.app.service.EleveManager;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Implementation of RoleManager interface.
 *
 * @author <a href="mailto:dan@getrolling.com">Dan Kibler</a>
 */
@Service("eleveManager")
public class EleveManagerImpl extends GenericManagerImpl<Eleve, Long> implements EleveManager {
    EleveDao eleveDao;

    @Autowired
    public EleveManagerImpl(EleveDao eleveDao) {
        super(eleveDao);
        this.eleveDao = eleveDao;
    }

    @Override
    public List<Eleve> getAll(){
    	return eleveDao.getAll();
    }
	@Override
	public List<Eleve> searchCustom(Eleve eleve) {
		//check given eleve
		if((eleve.getGroupe() != null && eleve.getGroupe().getId() != null && eleve.getGroupe().getId() > 0)
				|| StringUtils.isNotEmpty(eleve.getNom())
				|| StringUtils.isNotEmpty(eleve.getPrenom())
				|| StringUtils.isNotEmpty(eleve.getNumeroInscription()))
				return eleveDao.searchCustom(eleve);
		else
			return new ArrayList<>();
					
	}

	@Override
	public Eleve loadEleveByNumeroInscription(String numeroInscription) {
		return eleveDao.loadEleveByNumeroInscription(numeroInscription);
	}

	@Override
	public void deleteEleve(Long id) {
		eleveDao.deleteEleve(id);
	}

	@Override
	public List<Eleve> getListEleveRetardPay() {
		return eleveDao.getListEleveRetardPay();
	}

	@Override
	public Number getSizeAll() {
		return eleveDao.getSizeAll();
	}

	@Override
	public List<Eleve> getAllWithoutExonere() {
		return eleveDao.getAllWithoutExonere();
	}

}